package thread;

import java.util.Scanner;

public class Demo17 {
    public static void main(String[] args) {
        Object locker = new Object();
        Thread t1 = new Thread(() -> {
            System.out.println("wait之前");
            try {
                synchronized (locker) {
                    locker.wait();
                }
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println("wait之后");
        });
        Thread t2 = new Thread(() -> {
            Scanner sc = new Scanner(System.in);
            System.out.println("输入任意内容启动notify");
            //输入流会有一个阻塞效果,使的线程1中的wait先被执行，
            // 完成notify在wait之后被执行
            sc.next();
            synchronized (locker) {
                locker.notify();
            }
        });
        t1.start();
        t2.start();
    }
}
